{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "f223f864",
   "metadata": {},
   "outputs": [],
   "source": [
    "found = {}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "8e160208",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function pop:\n",
      "\n",
      "pop(...) method of builtins.dict instance\n",
      "    D.pop(k[,d]) -> v, remove specified key and return the corresponding value.\n",
      "    \n",
      "    If key is not found, default is returned if given, otherwise KeyError is raised\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(found.pop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "bc74dceb",
   "metadata": {},
   "outputs": [],
   "source": [
    "##Pop(…)内置函数的方法。 dict实例  \n",
    "##d .pop(k[，d]) -> v，删除指定的键并返回相应的值。  \n",
    " \n",
    "##如果key未找到，则返回default，否则抛出KeyError  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "17a7c3fe",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function keys:\n",
      "\n",
      "keys(...) method of builtins.dict instance\n",
      "    D.keys() -> a set-like object providing a view on D's keys\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(found.keys)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "9d2239fe",
   "metadata": {},
   "outputs": [],
   "source": [
    "#内置函数的Keys(…)方法。 dict实例  \n",
    "#D.keys() ->一个类似集合的对象，提供D的键的视图  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "3b741d11",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function clear:\n",
      "\n",
      "clear(...) method of builtins.dict instance\n",
      "    D.clear() -> None.  Remove all items from D.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(found.clear)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "7a526fd7",
   "metadata": {},
   "outputs": [],
   "source": [
    "#清除内置函数的(…)方法。 dict实例  \n",
    "#D.clear() - >没有。 删除D中的所有项目。  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "e52d58c0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function copy:\n",
      "\n",
      "copy(...) method of builtins.dict instance\n",
      "    D.copy() -> a shallow copy of D\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(found.copy)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "id": "f47b0745",
   "metadata": {},
   "outputs": [],
   "source": [
    "#内置函数的Copy(…)方法。 dict实例  \n",
    "# D.copy() ->一个D的浅拷贝\n",
    "# 备份拷贝"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "id": "0815fb18",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function get:\n",
      "\n",
      "get(key, default=None, /) method of builtins.dict instance\n",
      "    Return the value for key if key is in the dictionary, else default.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(found.get)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "id": "29039079",
   "metadata": {},
   "outputs": [],
   "source": [
    "#get(key, default=None， /)内置函数的方法。 dict实例  \n",
    "#如果key在字典中，返回key的值，否则默认。 \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "id": "da21d60a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function items:\n",
      "\n",
      "items(...) method of builtins.dict instance\n",
      "    D.items() -> a set-like object providing a view on D's items\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(found.items)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "id": "2feeeca9",
   "metadata": {},
   "outputs": [],
   "source": [
    "#内置函数的Items(…)方法。 dict实例  \n",
    "#>一个类似集合的对象，提供D项的视图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "cd1a0d4c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function popitem:\n",
      "\n",
      "popitem() method of builtins.dict instance\n",
      "    Remove and return a (key, value) pair as a 2-tuple.\n",
      "    \n",
      "    Pairs are returned in LIFO (last-in, first-out) order.\n",
      "    Raises KeyError if the dict is empty.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(found.popitem)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "id": "94409cc2",
   "metadata": {},
   "outputs": [],
   "source": [
    "#内置项的Popitem()方法。 dict实例  \n",
    "#移除并返回一个(键，值)对为2元组。   \n",
    "#对按后进先出(后进先出)顺序返回。  \n",
    "#如果字典为空则引发KeyError异常"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "id": "319b97d5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function values:\n",
      "\n",
      "values(...) method of builtins.dict instance\n",
      "    D.values() -> an object providing a view on D's values\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(found.values) #查看所有值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "id": "88a8cc8f",
   "metadata": {},
   "outputs": [],
   "source": [
    "#关于内置函数值的帮助:  \n",
    "#Values(…)方法。 dict实例  \n",
    "#D.values() ->一个提供D值视图的对"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "id": "77d666a4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function setdefault:\n",
      "\n",
      "setdefault(key, default=None, /) method of builtins.dict instance\n",
      "    Insert key with a value of default if key is not in the dictionary.\n",
      "    \n",
      "    Return the value for key if key is in the dictionary, else default.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(found.setdefault)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "id": "17fc8a65",
   "metadata": {},
   "outputs": [],
   "source": [
    "#内置函数setdefault的帮助:   \n",
    "#setdefault(key, default=None， /)内置函数的方法。 dict实例。 如果key不在字典中，则用default值插入key。 如果key在字典中，返回key的值，否则默认。  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "id": "6f98d40a",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function update:\n",
      "\n",
      "update(...) method of builtins.dict instance\n",
      "    D.update([E, ]**F) -> None.  Update D from dict/iterable E and F.\n",
      "    If E is present and has a .keys() method, then does:  for k in E: D[k] = E[k]\n",
      "    If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v\n",
      "    In either case, this is followed by: for k in F:  D[k] = F[k]\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(found.update)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "id": "668a2ef1",
   "metadata": {},
   "outputs": [],
   "source": [
    "#内置函数的Update(…)方法。 dict实例  \n",
    "#D.update([E，]**F) ->无。 从dict/iterable E和F中更新D。  \n",
    "#for k in E: D[k] = E[k]  \n",
    "#如果E存在且缺少.keys()方法，则执行:for k, v in E: D[k] = v  \n",
    "#在这两种情况下，后面跟着:for k In F: D[k] = F[k]  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "id": "30919f01",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'bar': 3, 'egg': 2, 'spam': 1}"
      ]
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list = [('spam', 1), ('egg', 2), ('bar', 3)]\n",
    "dic = dict(list)\n",
    "dic\n",
    "{'bar': 3, 'egg': 2, 'spam': 1}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "id": "ff3f19df",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_values([1, 2, 3])"
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dic.values() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "id": "e89ec80d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 108,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dic.setdefault(\"bar\",6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "id": "4f05d9df",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'spam': 1, 'egg': 2, 'bar': 3}"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "id": "b7876e32",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 不变"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "id": "94225818",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dic.setdefault(\"tes\",6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "id": "1efe2d82",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'spam': 1, 'egg': 2, 'bar': 3, 'tes': 6}"
      ]
     },
     "execution_count": 112,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "id": "bfc8015b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 113,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dic.get(\"tes\") #不变 查值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "id": "f9868d6d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 114,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dic.get(\"rng\",8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "id": "2e31d415",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'spam': 1, 'egg': 2, 'bar': 3, 'tes': 6}"
      ]
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dic  #get只是查值 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "id": "e98d77c7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_items([('spam', 1), ('egg', 2), ('bar', 3), ('tes', 6)])"
      ]
     },
     "execution_count": 116,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dic.items()  #查出项目列表内容 返回可遍历的(键, 值) 元组数组。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "id": "13c09c68",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['spam', 'egg', 'bar', 'tes'])"
      ]
     },
     "execution_count": 117,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dic.keys()  #查keys名"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "id": "b6e63c51",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 118,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dic.pop(\"egg\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "id": "b77e609b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'spam': 1, 'bar': 3, 'tes': 6}"
      ]
     },
     "execution_count": 119,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "id": "91a7209d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('bar', 3)"
      ]
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dic.popitem() #随机"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "id": "186615de",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'spam': 1, 'bar': 3}"
      ]
     },
     "execution_count": 122,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "id": "24a0f5c2",
   "metadata": {},
   "outputs": [],
   "source": [
    "#最后清除列表  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6257cfd1",
   "metadata": {},
   "outputs": [],
   "source": [
    "dic.clear()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "47d8e039",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 表格 markdown"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "02c010a0",
   "metadata": {},
   "source": [
    "| 方法名      | 用法| 实例|\n",
    "| :----: | :---   | :----: |\n",
    "| pop      |   D.pop (k [d])→V，移除指定的键并返回对应的值。如果key未找到，则返回default，否则抛出KeyError |dic.pop(\"tes\")|\n",
    "| get      | 如果key在字典中，返回key的值，否则默认。      |dic.get(\"rng\",8)|\n",
    "|keys    |   D.keys() ->一个类似集合的对象，提供D的键的视图      |dic.keys() |\n",
    "|values     |D.values() ->一个提供D值视图的对象|dic.values() |\n",
    "|clear     | 删除D中的所有项目。|dic.clear()|\n",
    "| items     |一个类似集合的对象，提供D项的视图|dic.items() |\n",
    "|setdefault  |如果key不在字典中，则用default值插入key。如果key在字典中，返回key的值，否则默认。|dic.setdefault(\"tes\",6)|\n",
    "|popitem | 随机删除一个值|dic.popitem()|\n",
    "| update |update() 函数把字典dict2的键/值对更新到dict里。有相同的键会直接替换成 update 的值|dic.update()|\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "56be27a6",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
